package com.caigou.modules.famous.adpter

import android.graphics.Color
import android.text.TextUtils
import android.widget.ProgressBar
import android.widget.TextView
import com.caigou.comm.base.utils.ImageLoader
import com.caigou.modules.famous.R
import com.caigou.modules.famous.bean.FamousItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @author #Suyghur.
 * Created on 2021/12/08
 */
class FamousItemAdapter(dataset: MutableList<FamousItemBean>) : BaseQuickAdapter<FamousItemBean, BaseViewHolder>(R.layout.item_famous_list, dataset) {
    init {
        addChildClickViewIds(R.id.item_famous_ll_like)
        addChildClickViewIds(R.id.item_famous_ll_subscribe)
    }

    override fun convert(holder: BaseViewHolder, item: FamousItemBean) {
        if (TextUtils.isEmpty(item.headImg)) {
            holder.setImageResource(R.id.item_famous_iv_avatar, R.drawable.img_comm_avatar)
        } else {
            ImageLoader.loadCircle(context, item.headImg, holder.getView(R.id.item_famous_iv_avatar))
        }

        holder.setText(R.id.item_famous_tv_nickname, item.nickName)
        holder.setText(R.id.item_famous_tv_time, item.createTime)
        holder.setText(R.id.item_famous_tv_record, "战绩：${item.count}对${item.successCount}")
        holder.setText(R.id.item_famous_tv_desc, "第${item.period}期：${item.contentDetail}")
        holder.setText(R.id.item_famous_tv_rate, "正确率${item.accuracy}%")
        holder.getView<ProgressBar>(R.id.item_famous_process_bar_rate).progress = item.accuracy

        if (item.like) {
            holder.setImageResource(R.id.item_famous_iv_like, R.drawable.img_famous_like)
            holder.getView<TextView>(R.id.item_famous_tv_like_num).setTextColor(Color.parseColor("#FE6880"))
        } else {
            holder.setImageResource(R.id.item_famous_iv_like, R.drawable.img_famous_unlike)
            holder.getView<TextView>(R.id.item_famous_tv_like_num).setTextColor(Color.parseColor("#B9B9B9"))
        }
        holder.setText(R.id.item_famous_tv_like_num, item.nicePoint.toString())

        if (item.subscribe) {
            holder.setImageResource(R.id.item_famous_iv_subscribe, R.drawable.img_famous_subscribed)
            holder.getView<TextView>(R.id.item_famous_tv_subscribe).setTextColor(Color.parseColor("#FE6880"))
        } else {
            holder.setImageResource(R.id.item_famous_iv_subscribe, R.drawable.img_famous_subscribe)
            holder.getView<TextView>(R.id.item_famous_tv_subscribe).setTextColor(Color.parseColor("#B9B9B9"))
        }
    }
}